/*
 * AY 2014/15 Semester 1 IS2103 Assignment Part2
 * Matric. No.:    A0102330H
 * Name:           Cui Lin
 */
package ejb;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Topic;

/**
 *
 * @author cuilin
 */
@Stateless
public class AMSManagerBean implements AMSManagerBeanRemote {

    @Resource(mappedName = "jms/TopicConnectionFactory")
    private ConnectionFactory topicConnectionFactory;
    @Resource(mappedName = "jms/Topic")
    private Topic topic;

    @Override
    public void createAppeal(String matricNum, String content) {
        try {
            Connection topicConnection = topicConnectionFactory.createConnection();
            Session session = topicConnection.createSession(false, 0);
            MessageProducer producer = session.createProducer(topic);
            MapMessage msg = session.createMapMessage();
            msg.setString("matricNum", matricNum);
            msg.setString("content", content);
            producer.send(msg);
            
        } catch (Exception ex) {
            System.out.println("AMSManagerBean: createSuggestion(): Caught an unexpected exception: " + ex.toString());
        }
    }
}
